Component({
    properties: {
        item: {
            type: Object,
            value: {}
        },
        name: {
            type: Number,
            value: 0
        },
        level: {
            type: [ String, Number ],
            value: 1
        }
    },
    relations: {
        "./collapse": {
            type: "parent",
            linked: function(t) {
                this.parent = t;
            },
            linkChanged: function(t) {},
            unlinked: function(t) {}
        }
    },
    data: {
        flag: !1,
        height: 0,
        expanded: !1
    },
    ready: function() {
        this.animation = wx.createAnimation({
            duration: 0,
            timingFunction: "ease-in-out"
        });
    },
    methods: {
        handOperation: function() {
            this.triggerEvent("operation", {
                name: this.data.name,
                level: this.data.level
            });
        },
        onClick: function() {
            this.setData({
                flag: !this.data.flag
            }), this.updateStyle(this.data.flag);
        },
        updateExpanded: function() {
            if (!this.parent) return Promise.resolve();
            var t = this.parent.data.active, e = this.data.name, n = (t || []).some(function(t) {
                return t === e;
            });
            n !== this.data.expanded && this.updateStyle(n), this.setData({
                expanded: n
            });
        },
        updateStyle: function(t) {
            var e = this;
            this.getRect(".collapseContent").then(function(t) {
                return t.height;
            }).then(function(n) {
                var a = e.animation;
                if (t) return 0 === n ? a.height("auto").top(1).step() : a.height(n).top(1).step({
                    duration: 300
                }).height("auto").step(), void e.setData({
                    animation: a.export()
                });
                a.height(n).top(0).step({
                    duration: 1
                }).height(0).step({
                    duration: 300
                }), e.setData({
                    animation: a.export()
                });
            });
        },
        getRect: function(t) {
            var e = this;
            return new Promise(function(n, a) {
                e.createSelectorQuery().select(t).boundingClientRect(function(e) {
                    e ? n(e) : a(new Error("can not find selector: " + t));
                }).exec();
            });
        }
    }
});